/* =======================================================
   0. ROOT VARIABLES & GLOBALS
   ======================================================= */

:root {
  /* Fonts */
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Colors */
  --bg: radial-gradient(circle at top, #24263a, #060509);
  --text: #eeeeee;
  --text-dim: #b5b5b5;
  --border-soft: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.2);
  --panel-bg: rgba(255, 255, 255, 0.04);
  --panel-bg-hover: rgba(139, 166, 177, 0.08);
  --input-bg: rgba(255, 255, 255, 0.07);
  --input-border: rgba(255, 255, 255, 0.2);
  --chat-bubble: rgba(255, 255, 255, 0.08);
  --chat-bubble-user: #4e8cff;
  --dropdown-bg: rgba(20, 20, 20, 0.95);
  --selection-text: rgb(142, 88, 203); /* bright purple text-only selection */

  /* Misc */
  --radius: 10px;
  --transition-fast: 0.2s ease;
  --transition-med: 0.35s ease;
}

:root {
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body,
input,
textarea,
select,
button {
  font-family: var(--font-ui);
  font-size: 15px;
}

/* Global selection (text-only purple) */
::selection,
::-moz-selection {
  background: rgba(0, 0, 0, 0);
  color: var(--selection-text);
}

/* =======================================================
   1. BODY & MAIN LAYOUT
   ======================================================= */

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: block;
  padding: 2rem;
}

/* Main 3-panel layout */
#armonia-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 2.5rem;
  width: 100%;
  padding: 2rem;
}

/* Shared panel styling (Help, Lyric, Thesaurus) */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 1.4rem;
  flex: 1;
  max-width: 360px;
  min-width: 200px;
  transition: background-color var(--transition-med);
}

.panel:hover,
.panel:active {
  background: var(--panel-bg-hover);
}

.panel h2 {
  font-size: 1.4rem;
  margin-top: 0;
}

/* =======================================================
   2. HELP CHAT (LEFT PANEL)
   ======================================================= */

#help-chat {
  margin-bottom: 2rem;
}

/* Chat log container */
#help-chat-log {
  background: rgba(255, 255, 255, 0.05);
  padding: 1rem;
  border-radius: 10px;
  max-height: 380px;
  overflow-y: auto;
  margin-bottom: 1rem;
  scrollbar-width: none;
}

#help-chat-log::-webkit-scrollbar {
  display: none; /* Chrome, Edge, Safari */
}

/* Chat input row (textarea + button) */
.chat-input-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

/* Chat input textarea */
#help-chat-input {
  width: 100%;
  min-height: 40px;
  max-height: 160px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  resize: none; /* we auto-expand via JS */
}

/* Chat send button */
#help-chat-send {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

#help-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

#help-chat-send:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

/* Chat message rows & bubbles */
.msg-row {
  display: flex;
  margin-bottom: 0.5rem;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.assistant {
  justify-content: flex-start;
}

.msg-bubble {
  background: var(--chat-bubble);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  white-space: pre-wrap;
  max-width: 75%;
}

.msg-row.user .msg-bubble {
  background: var(--chat-bubble-user);
  color: #ffffff;
}

/* Fix lists inside chat bubbles */
.msg-bubble ol,
.msg-bubble ul {
    margin: 0 0 0 10px;   /* smaller indentation */
    padding: 0;
}

.msg-bubble li {
    margin: 4px 0;
}

/* Typing indicator */
.msg-bubble.typing-bubble {
  padding: 8px 8px !important;
  min-height: unset !important;
  height: auto !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.05);
}

.typing-dots {
  display: inline-flex;
  /* height: 1rem; */
  gap: 3px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: #aaaaaa;
  border-radius: 50%;
  animation: typing-blink 1.4s infinite both;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-blink {
  0% {
    opacity: 0.2;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0.2;
  }
}

/* =======================================================
   3. LYRIC WRITER (MIDDLE PANEL)
   ======================================================= */

#lyric-writer {
  margin-bottom: 2rem;
  border: 1px solid var(--border-soft);
}

/* Dialect dropdown */
#dialect-select {
  width: 100%;
  margin: 0.5rem 0 0.75rem 0;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

/* Container */
#dialect-multiselect {
  position: relative;
  width: 100%;
  margin-bottom: 1rem;
  user-select: none;
}

/* Display Row (same as Genre) */
#dialect-display {
  background: rgba(255, 255, 255, 0.06);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: background 0.15s;
}

#dialect-display:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Dropdown Box */
#dialect-dropdown {
  position: absolute;
  top: 105%;
  left: 0;
  width: 100%;
  background: rgba(20, 20, 20, 0.95);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 10px;
  z-index: 200;
}

#dialect-dropdown.hidden {
  display: none;
}

/* Each option */
.dialect-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  color: #eee;
}

.dialect-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.dialect-item.selected {
  background: rgba(77,163,255,0.3);
  font-weight: bold;
}

/* Make dropdown lists consistent */
.dropdown-list {
  position: absolute;
  top: 105%;
  left: 0;
  width: 100%;
  background: rgba(20, 20, 20, 0.97);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px;
  z-index: 200;
  font-size: 0.92rem;          /* smaller text */
}

/* SINGLE-COLUMN (Dialect) - this is default */
#dialect-dropdown {
  display: flex;
  flex-direction: column;
  gap: 4px;                    /* tighter spacing */
}

/* GENRE DROPDOWN: Two-column layout */
#genre-dropdown {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 2 columns */
  row-gap: 4px;                /* tighter spacing */
}

/* Item appearance */
.dropdown-item {
  padding: 6px 8px;            /* smaller height */
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1.2;            /* tighter line spacing */
}

.dropdown-item:hover {
  background: rgba(255,255,255,0.1);
}

.dropdown-item.selected {
  background: rgba(77,163,255,0.3);
  font-weight: 600;
}

/* Remove scrollbar ALWAYS */
#genre-dropdown::-webkit-scrollbar,
#dialect-dropdown::-webkit-scrollbar {
  display: none;
}

#genre-dropdown,
#dialect-dropdown {
  scrollbar-width: none; /* Firefox */
}


/* Genre multiselect container */
#genre-multiselect {
  margin-bottom: 1rem;
  position: relative;
  width: 100%;
  user-select: none;
}

/* Display row for genres */
#genre-display {
  background: rgba(255, 255, 255, 0.06);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: background var(--transition-fast);
}

#genre-display:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Genre dropdown list */
#genre-dropdown {
  position: absolute;
  top: 105%;
  left: 0;
  width: 100%;
  background: var(--dropdown-bg);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 10px;
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
}

#genre-dropdown.hidden {
  display: none;
}

/* Genre item rows */
#genre-dropdown .item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}

#genre-dropdown .item:hover {
  background: rgba(255, 255, 255, 0.1);
}

#genre-dropdown .item.selected {
  background: rgba(77, 163, 255, 0.3);
  font-weight: bold;
  color: #ffffff;
}

/* Sliders */
.slider-label {
  margin-top: 4px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* All range sliders in lyric writer */
input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  background: #4da3ff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(77, 163, 255, 0.6);
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Lyric input */
#lyric-input {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: #eeeeee;
  outline: none;
  resize: vertical;
  margin-bottom: 1rem;
}

/* Lyric output */
#lyric-output {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  color: #dddddd;
  white-space: pre-wrap;
}

/* Lyric + Thesaurus buttons (share similar style) */
#lyric-generate,
#synonym-analyze {
  padding: 8px 14px;
  margin-top: 0.5rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

#lyric-generate:hover,
#synonym-analyze:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

/* =======================================================
   4. THESAURUS TOOL (RIGHT PANEL)
   ======================================================= */

#line-numbers,
#synonym-input {
  font-family: var(--font-mono);
}

/* Line editor wrapper: numbers + textarea */
.line-editor {
  position: relative;
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  overflow: hidden;
}

/* Left gutter with line numbers */
#line-numbers {
  padding: 8px 6px;
  text-align: right;
  user-select: none;
  color: #777777;
  background: rgba(0, 0, 0, 0.2);
  line-height: 1.4em;
  display: inline-block;
  white-space: pre;
}

/* Synonym textarea */
#synonym-input {
  flex: 1;
  padding: 8px;
  border: none;
  resize: none;
  background: transparent;
  color: #eeeeee;
  line-height: 1.4em;
  outline: none;
}

/* Synonym result box */
#synonym-output {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

/* Highlighted active line */
#active-line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  height: 1.5em; /* close to line-height; tuned visually */
  background: rgba(222, 194, 255, 0.06);
  pointer-events: none;
  border-radius: 4px;
  display: none; /* shown via JS when active */
}

/* =======================================================
   5. HIDDEN MIRRORS (MEASUREMENT ONLY)
   ======================================================= */

#synonym-mirror,
#caret-mirror {
  position: absolute;
  top: -9999px;
  left: -9999px;
  visibility: hidden;

  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;

  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.4em;
  padding: 8px;
  box-sizing: border-box;
}
